package sz.szsmk.citizencard.ui.fragment;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.ServiceTypeFragmentBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.response.PrepayResponse;
import sz.szsmk.citizencard.mvp.contract.IAllTypeContact;
import sz.szsmk.citizencard.mvp.presenter.AllTypePresenter;
import sz.szsmk.citizencard.ui.adapter.AllTypeAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;
import sz.szsmk.citizencard.util.Constant;

import java.util.List;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/12 10:02
 * description:
 */
public class ServiceTypeFragment extends IBaseFragment<AllTypePresenter, ServiceTypeFragmentBinding>
        implements IAllTypeContact.IAllTypeView {

    private AllTypeAdapter allTypeAdapter;

    public static ServiceTypeFragment getInstance() {
        ServiceTypeFragment sf = new ServiceTypeFragment();
        return sf;
    }


    @Override
    protected int attachLayoutRes() {
        return R.layout.service_type_fragment;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        RecyclerView allTypeRv = dataBinding.allTypeRv;
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        allTypeRv.setLayoutManager(linearLayoutManager);
        allTypeAdapter = new AllTypeAdapter(getActivity());
        allTypeRv.setAdapter(allTypeAdapter);
//        mPresenter.prepayWebsiteList();
//        mPresenter.prepayWebsiteList();

    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void updataError() {

    }

    @Override
    public void getNewsInfoSucc() {

    }

    @Override
    public void prepaySuccess(PrepayResponse response) {
        L.e(Constant.TAG,"=============================================");
        if (response == null){
            return;
        }
        setTypeData(response);
    }

    private void setTypeData(PrepayResponse response) {
        if (response == null){
            return;
        }
        List<PrepayResponse.WebsiteListInfoBean> websiteListInfo = response.getWebsiteListInfo();
        if (websiteListInfo == null){
            return;
        }
        allTypeAdapter.setTypeData(websiteListInfo,0);
        allTypeAdapter.notifyDataSetChanged();
    }

    @Override
    public void prepayFaile(PrepayResponse response) {

    }

    @Override
    public void websiteInfoSuccess() {

    }

    @Override
    public void websiteInfoFaile() {

    }


}
